
import random
import string
import time
from urllib.parse import urlencode
import hmac
from hashlib import sha1

def time_cuo():
    t = time.time()
    # print(int(t))
    timee = int(t)
    # print(str(timee))
    return str(timee)

# time_cuo()
def ranstr(num):
    salt = ''.join(random.sample(string.ascii_letters + string.digits, num))
    return str(salt)
# salt = ranstr(32)
# print(salt)

def signature():
    header = {
     "appid": "daofengdj_android",
     "deviceid": "284b16fe3bc201bf",
     # "nonce": ranstr(32),    #随机字符串，每次重新生成，位数32位，推荐使用随机数md5
     "nonce": 'b23a7914ee59efc06674e0c8165e0a5f',    #随机字符串，每次重新生成，位数32位，推荐使用随机数md5
     # "timestamp": time_cuo(), #当前的时间戳 （10位时间戳，单位是秒）
     "timestamp": '1631583675', #当前的时间戳 （10位时间戳，单位是秒）
     "versions": "4.4.0"
    }
    header.items()
    print(urlencode(header))
    return urlencode(header)

# signature()

def hash_hmac(key, code, sha1):
    hmac_code = hmac.new(key.encode(), code.encode(), sha1)
    print(hmac_code.hexdigest())
    return hmac_code.hexdigest()

a = 'appid%3Ddaofengdj_ios%26deviceid%3D6A1E1D8C-EF4B-4763-9DF9-78E6EA809DE0%26nonce%3D8fa14cdd754f91cc6554c9e71929cce7%26timestamp%3D1517564053%26versions%3D2.8'
hash_hmac('88a597ec16db72c47df6449958841d2229d023f5', a, sha1)
